//
//  KLDoctorDetailViewController.m
//  KunLun
//
//  Created by Mac on 2017/12/27.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "KLDoctorDetailViewController.h"

@interface KLDoctorDetailViewController ()

@end

@implementation KLDoctorDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"医生详情";
    [self configSubView];
    [self configBootomView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 300)];
    header.backgroundColor = [UIColor whiteColor];
    
    UIImageView * imagView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 145)];
    [imagView sd_setImageWithURL:[NSURL URLWithString:self.model.header] completed:nil];
    imagView.userInteractionEnabled = YES;
    [header addSubview:imagView];
    
    UIVisualEffectView * visouView = [[UIVisualEffectView alloc] initWithFrame:imagView.bounds];
    visouView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    [imagView addSubview:visouView];
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(30, 0, 80, 80)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:40
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    [iconButton sd_setBackgroundImageWithURL:[NSURL URLWithString:self.model.header] forState:UIControlStateNormal];
    iconButton.centerY = imagView.height / 2;
    [header addSubview:iconButton];
    
    STLabel * nameLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right  +10, iconButton.top  +5, 200, 16)
                                                     text:self.model.name
                                                textColor:[UIColor whiteColor]
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [imagView addSubview:nameLable];
    
    STLabel * typeLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right  +10, nameLable.bottom  +5, 200, 16)
                                                    text:self.model.department
                                               textColor:[UIColor whiteColor]
                                                    font:14
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [imagView addSubview:typeLable];
    
    STLabel * phoneLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right  +10, typeLable.bottom  +5, 200, 16)
                                                    text:self.model.phone
                                               textColor:[UIColor whiteColor]
                                                    font:14
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [imagView addSubview:phoneLable];
    
    STLabel * goodLable = [[STLabel alloc] initWithFrame:CGRectMake(self.insetX, imagView.bottom, UIScreenWidth, 44)
                                                    text:@"擅长:"
                                                textColor:[UIColor blackColor]
                                                     font:18
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:goodLable];
    
    STLabel * goodDesLable = [[STLabel alloc] initWithFrame:CGRectMake(self.insetX, goodLable.bottom  , UIScreenWidth - 2 * self.insetX, 20)
                                                    text:self.model.adept
                                               textColor:KL_firstTextColor
                                                    font:15
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [header addSubview:goodDesLable];
    [NSString lableAutoAdjustheightWithLabel:goodDesLable];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, goodDesLable.bottom + 20,  UIScreenWidth, 0.5)];
    line.backgroundColor = KL_backgroundColor;
    [header addSubview:line];
    
    
    STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(self.insetX, line.bottom, UIScreenWidth, 44)
                                                    text:@"简介:"
                                               textColor:[UIColor blackColor]
                                                    font:18
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [header addSubview:desLable];
    
    STLabel * mydesLable = [[STLabel alloc] initWithFrame:CGRectMake(self.insetX, desLable.bottom  +10, UIScreenWidth - 2 * self.insetX, 20)
                                                       text:self.model.introduce
                                                  textColor:KL_firstTextColor
                                                       font:15
                                                isSizetoFit:NO
                                              textAlignment:NSTextAlignmentLeft];
    [header addSubview:mydesLable];
    [NSString lableAutoAdjustheightWithLabel:mydesLable];
    
    
    CGFloat top = mydesLable.bottom +10;
    for (int i =0; i < self.model.pictures.count; i ++) {
        UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, top, UIScreenWidth - 40, 170)];
        [imageView sd_setImageWithURL:[NSURL URLWithString:self.model.pictures[i]]];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        [header addSubview:imageView];
        top = imageView.bottom + 10;
    }
    header.height = top + 10 + 49;
    self.tableView.tableHeaderView = header;
}
- (void)configBootomView{
    self.tableView.height = self.tableView.height - 49;
    STButton * contactButton = [[STButton alloc] initWithFrame:CGRectMake(0, [KLUtils tabBarTop], UIScreenWidth, 49)
                                                     title:@"立即咨询"
                                                titleColor:[UIColor whiteColor]
                                                 titleFont:18
                                              cornerRadius:0
                                           backgroundColor:KL_BlueBackGroundColor
                                           backgroundImage:nil
                                                     image:nil];
    contactButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    __weak typeof(self) weakSelf =  self;
    [contactButton setClicAction:^(UIButton *sender) {
        [weakSelf onselctedContact];
    }];
    [self.view addSubview:contactButton];
}
#pragma mark --Action Method
- (void)onselctedContact{
    NSString * phone = self.model.phone ;
    BOOL isSelf =  [[STUserManger defult].phone isEqualToString:phone];
    if (isSelf) {
        [SVProgressHUD showInfoWithStatus:@"这是你自己发布的信息"];
        return;
    }
    KLMessageChatViewController * vc = [[KLMessageChatViewController alloc] initWithConversationChatter:phone conversationType:EMConversationTypeChat];
    [self.navigationController pushViewController:vc animated:YES];
}
@end
